import os

from appium import webdriver

from lagou_cekai.task3_3appium2.ten_class_Enterprise_wechat.page.base_page import BasePage33
from lagou_cekai.task3_3appium2.ten_class_Enterprise_wechat.page.page_function.fun_mian_page import MianPage33


class App(BasePage33):
    def stat(self):
        # 接收外部windows输入的参数
        # udid=os.getenv("udid")
        # port=os.getenv("port")
        if self.driver==None:
            caps={
                "platformName":"Android",
                "appPackage":"com.tencent.wework",
                "appActivity":".launch.LaunchSplashActivity",
                "deviceName":"hogwarts",
                # "udid":udid,
                "noReset":True,
                'skipServerInstallation':True,
                'skipDeviceInitialization':True,
                # True和'true'都是生效的
                'dontStopAppOnReset':"true"
            }
            self.driver = webdriver.Remote(f"http://127.0.0.1:7555/wd/hub",caps)
            # self.driver = webdriver.Remote(f"http://127.0.0.1:{port}/wd/hub",caps)
            self.driver.implicitly_wait(5)
        else:
            # 复用driver，启动app
            # launch_app()不需要传递任何参数，启动driver里设置好的activity
            self.driver.launch_app()
        return self

    def stop(self):
        self.driver.quit()

    def restart(self):
        self.driver.close_app()
        self.driver.launch_app()

    def goto_main(self):
        return MianPage33(self.driver)
